import { BaseUrl } from "./constant";

/*
 * @Author: wuqiang
 * @Date: 2023-11-11 13:36:18
 * @LastEditors: wuqiang
 * @LastEditTime: 2023-11-17 16:10:46
 */
export class API {
  static async get(url: string, body?: Record<string, any>) {
    return fetch(`${BaseUrl}${url}`, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json'
      }
    }).then(res => res.json()).then(res => {
      console.log('res =>', res);
    }).catch(e => {
      console.log('e =>', e);
    })
  }

  static async post(url: string, body: Record<string, any>) {
    return fetch(`${BaseUrl}${url}`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({"product": {
        "project": "PROG7417",
        "insurer": 3
      }, origin: 'tiancai', ...body})
    }).then(res => res.json()).then(res => {
      if (res.code === 200) {
        return [res.code, res.data]
      } else {
        return [res.code, res.message]
      }
    }).catch(e => {
      return [500, e.message]
    })
  }
}